

import requests
from bs4 import BeautifulSoup
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
}
# responses=requests.get(f"https://movie.douban.com/top250", headers=headers)
# print(responses.status_code)
with open('D:\桌面\\test.txt', 'w', encoding='utf-8') as file:
    for start_num in range(0,226,25):
        responses=requests.get(f"https://movie.douban.com/top250?start={start_num}",headers=headers)
        html=responses.text
        soup=BeautifulSoup(html,"html.parser")
        all_titles=soup.find_all("span",attrs={"class":"title"})
        for title in all_titles:
            title_string=title.string
            if "/" not in title_string:
                file.write(title_string+'\n')
                print(title_string)







